//
//  PostMediaCellData.m
//  CKApp
//
//  Created by CC on 2020/9/12.
//  Copyright © 2020 This Moment. All rights reserved.
//

#import "PostMediaCellData.h"
#import "PostMediaCell.h"
#import "LcFoundation.h"

@implementation PostMediaCellData

+ (instancetype)cellDataMediaMetas:(NSArray<CCMediaMeta*>*)mediaMetas
              deleteClickedHandler:(OnCollectionCellClickedHanlder)deleteClickedHandler
                 addClickedHandler:(OnCollectionCellClickedHanlder)addClickedHandler {
  PostMediaCellData* cellData = [[PostMediaCellData alloc] init];
  cellData.mediaMetas = mediaMetas;
  cellData.deleteClickedHandler = deleteClickedHandler;
  cellData.addClickedHandler = addClickedHandler;
  cellData.cellHeight = [cellData calculateCellHeight];
  return cellData;
}

- (void)refreshCell:(__kindof PostMediaCell*)cell {
  [super refreshCell:cell];
  [cell refreshView:self.mediaMetas
      deleteClickedHandler:self.deleteClickedHandler
         addClickedHandler:self.addClickedHandler];
}

- (CGFloat)calculateCellHeight {
  CGFloat padding = 5.0;
  CGFloat itemWidth = (LcUIUtility.screenWidth - 36.0 - padding * 2) / 3.0;
  NSInteger rowCount = floor(self.mediaMetas.count / 3.0) + 1;
  return rowCount * itemWidth + (rowCount - 1) * padding;
}

@end
